//#define __DEBUG__
#define THIS_FILE "fn_arrayinsert.sqf"
#include "x_setup.sqf"

/************************************************************
	Array Insert
	By Andrew Barron

Parameters: [base array, insert array, index]
Returs: [array]

Inserts the elements of one array into another, at a specified
index.

Neither arrays are touched by reference, a new array is returned.

Example: [[0,1,2,3,4], ["a","b","c"], 1] call FUNC(arrayInsert)
Returns: [0,"a","b","c",1,2,3,4]
************************************************************/

private ["_baseArray","_toInsert","_index","_ret"];
PARAMS_3(_baseArray,_toInsert,_index);
if (_index > 0) then {
	_ret = [_baseArray, 0, _index-1] call FUNC(subSelect);
	[_ret, _toInsert] call FUNC(arrayPushStack2);
} else {
	_ret = _toInsert;
};
[_ret, [_baseArray, _index] call FUNC(subSelect)] call FUNC(arrayPushStack2);
_ret